**** Project: HOW PREJUDICE SHAPES PUBLIC PERCEPTIONS OF MINORITY-ORGANIZED SPACES: THE CASE OF COMMUNITY EDUCATION
**** Published in: Journal of Ethnic and Migration Studies
**** Study: Observational Study
**** Authors: Julia Steenwegen & Maurits J. Meijers
**** Date: 26 March, 2024

import spss using "data.sav", clear

**************************
*** Select Variables ***
**************************
keep StartDate EndDate Status Progress Duration__in_seconds_ Finished RecordedDate ResponseId gender birthyear education employment income urban_rural migration_background screener1_1 screener1_2 screener1_3 screener1_4 screener1_5 screener1_6 screener1_7 left_right screener2_1 screener2_2 screener2_3 screener2_4 screener2_5 screener2_6 study1_items_1 study1_items_2 study1_items_3 study1_items_4 study1_items_5 study1_items_6 study1_items_7 study1_items_8  multiculturalism_1 multiculturalism_2 multiculturalism_3 multiculturalism_4 multiculturalism_5 age_6_set edu_3_set groep weight_study1 weight_study1posthoc 

keep if weight_study1 != . // drop all observations not in Observational Study 

**************************
*** Creating Variables ***
**************************

* Reverse positive DVs 
gen study1_items_2rev = 8-study1_items_2
gen study1_items_5rev = 8-study1_items_5
gen study1_items_6rev = 8-study1_items_6
gen study1_items_7rev = 8-study1_items_7
gen study1_items_8rev = 8-study1_items_8

* Left-Right
*making DK/prefer not to say --> middle value
gen left_right2 = left_right
replace left_right2 = 5 if left_right == -99 

* Migration background  
gen migration_background_new = migration_background
replace migration_background_new = . if migration_background_new == -99

* Urban_rural
gen urban_rural_new = urban_rural
replace urban_rural_new = . if urban_rural_new == -99

* Education
encode edu_3_set, gen(edu3cat)

* Age 
gen age = 2023 - birthyear

* Income
gen income1 = income
replace income1 = . if income == -88 |  income == -99 

* factor variable for multiculturalism
factor  multiculturalism_1 multiculturalism_2 multiculturalism_3 multiculturalism_4 multiculturalism_5 [aweight=weight_study1], ipf mineigen(1) 

* Shows multiculturalism_3 doesnt scale well, factor with 4 vars only with aweight
factor  multiculturalism_1 multiculturalism_2  multiculturalism_4 multiculturalism_5 [aweight=weight_study1], ipf mineigen(1) 
rotate, blanks(.5) orthogonal varimax
predict multiculturalism_factor	
* --> higher values indicate support for multiculturalism

* factor variable for community education attitudes with aweight
factor  study1_items_1 study1_items_2rev study1_items_3 study1_items_4 study1_items_5rev study1_items_6rev study1_items_7rev study1_items_8rev [aweight=weight_study1], ipf mineigen(1) 
rotate, blanks(.5) orthogonal varimax
predict communityeducation_factor	
* -->  higher values indicate opposition to community schools

*Create community education DV ranging from 0-10
gen comed_fst = .
replace comed_fst = (communityeducation_factor - -2.312883) / (2.073318 - -2.312883)
gen comed_fst10 = comed_fst*10
gen multicult_fst = (multiculturalism_factor - -2.186439) / (1.620632 - -2.186439)

gen multicult_fst10 = multicult_fst*10

* Attention check
gen attention = 0
replace attention = 1 if screener2_3 == 1 & screener2_5 == 1

**************************
*** Labeling Variables ***
**************************
label variable study1_items_1 "Segregation"
label variable study1_items_2 "Integration"
label variable study1_items_2rev "Integration"
label variable study1_items_3 "Flemish identity"
label variable study1_items_4 "Concern"
label variable study1_items_5 "Heritage"
label variable study1_items_5rev "Heritage"
label variable study1_items_6 "Tutoring"
label variable study1_items_6rev "Tutoring"
label variable study1_items_7 "Achievement"
label variable study1_items_7rev "Achievement"
label variable study1_items_8 "Self-esteem"
label variable study1_items_8rev "Self-esteem"

label variable multiculturalism_factor "Multicultural Recognition"
label variable multicult_fst10 "Multicultural Recognition"
label variable comed_fst10 "Opposition to Community Education"
label variable left_right2 "Left-Right Self-Placement"
label variable edu3cat "Education"
label variable gender "Sex"
label variable age "Age"
label variable urban_rural_new "Residency"
label variable migration_background_new "Migration Background"
label var attention "Attentive"

label define edulabel 1 "Low Education" 2 "Mid Education" 3 "High Education"
label values edu3cat edulabel

label define genderlabel 1 "Male" 2 "Female" 
label values gender genderlabel

label define urbanrurallabel 1 "Large City" 2 "Suburbs" 3 "Town" 4 "Village" 5 "Countryside"
label values urban_rural_new urbanrurallabel

label define mblabel 1 "Migration Background" 2 "No Migration Background" 
label values migration_background_new mblabel

*******************************************
*** Figures and Tables in Manuscript ***
*******************************************

**** Figure 1 ****
* Density plot
multidensity gen study1_items_1 study1_items_2rev study1_items_3 study1_items_4 study1_items_5rev study1_items_6rev study1_items_7rev study1_items_8rev
multidensity juxta, recast(area)  opt1(lcolor(navy) color(navy%40)) opt2(lcolor(dkorange) color(dkorange%40)) opt3(lcolor(emerald) color(emerald%40))  opt4(lcolor(cranberry) color(cranberry%40)) opt5(lcolor(erose) color(erose%40)) opt6(lcolor(erose) color(erose%40)) opt7(lcolor(lavender) color(lavender%40)) opt8	(lcolor(teal) color(teal%40))  title("") xsc(r(1 7)) xla(1(1)7) ysc(r(0 .4)) yla(0(0.2).4)
drop _x1 _density1 _x2 _density2 _x3 _density3 _x4 _density4 _x5 _density5 _x6 _density6 _x7 _density7 _x8 _density8

*******************************************
*** Figures and Tables in Appendix ***
*******************************************
**** Table A1.1 ****
 *Tabs with weights 
tab gender
tab gender [aweight= weight_study1]
tab gender [aweight= weight_study1posthoc]

tab edu_3_set
tab edu_3_set [aweight= weight_study1]
tab edu_3_set [aweight= weight_study1posthoc]

tab age_6_set
tab age_6_set [aweight= weight_study1]
tab age_6_set [aweight= weight_study1posthoc]

**** Table A3.2 ****
* factor variable for community education attitudes with aweight
factor  study1_items_1 study1_items_2rev study1_items_3 study1_items_4 study1_items_5rev study1_items_6rev study1_items_7rev study1_items_8rev [aweight=weight_study1], ipf mineigen(1) 

**** Table A3.4 ****
* factor variable for multiculturalism
factor  multiculturalism_1 multiculturalism_2 multiculturalism_3 multiculturalism_4 multiculturalism_5 [aweight=weight_study1], ipf mineigen(1) 

**** Figure A3.1 ****
*Density plot for DV Study 1
multidensity gen comed_fst10
multidensity juxta, recast(area)  opt1(lcolor(navy) color(navy%40))

**** Table A3.5 ****
*OLS Model
estimates clear
reg comed_fst10 multicult_fst10 left_right2 i.edu3cat gender age i.urban_rural_new i.migration_background_new [pweight=weight_study1]
estimates store m1
esttab m1 using m1.csv, b(3) se(3) nomtitle wide label compress replace 

**** Table A3.6 ****
* With  weight 2
estimates clear
reg comed_fst10 multicult_fst10 left_right2 i.edu3cat gender age i.urban_rural_new i.migration_background_new [pweight=weight_study1posthoc]
estimates store m1w
esttab m1w using m1w.csv, b(3) se(3) nomtitle wide label compress replace 

* Attention Check
estimates clear
reg comed_fst10 multicult_fst10 left_right2 i.edu3cat gender age i.urban_rural_new i.migration_background_new [pweight=weight_study1] if attention==1
estimates store at1
reg comed_fst10 multicult_fst10 left_right2 i.edu3cat gender age i.urban_rural_new i.migration_background_new [pweight=weight_study1] if attention==0
estimates store at0

coefplot at1, bylabel(Attentive Sample)  ///
	|| at0, bylabel(Non-Attentive Sample) ///
		drop(_cons) xline(0) base msymbol(S)  ysize(2) xsize(5) coeflabels(,labsize(medlarge)) xlabel(, labsize(medlarge)) 		msize(medsmall) 
